package com.focusai.efairy.business.msg;

import android.content.Context;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.utils.PushJumpUtils;
import com.focusai.efairy.utils.log.Log;

import io.rong.push.notification.PushMessageReceiver;
import io.rong.push.notification.PushNotificationMessage;

/**
 * Created by Luogw on 2017/8/21.
 */

public class SealNotificationReceiver extends PushMessageReceiver  {
    public static final String TAG = SealNotificationReceiver.class.getName();
    private static final int DOWNLOAD_TAG = 1112;
    @Override
    public boolean onNotificationMessageArrived(Context context, PushNotificationMessage message) {
        Log.D(TAG,"融云推送消息过来了 message" + message.getPushContent());
        if (CacheManager.getUserMsgTip()){
            int notificationId = DOWNLOAD_TAG;
            if (message!=null && message.getTargetId() != null && message.getTargetId().startsWith("user_")){
                String tagid = message.getTargetId().replace("user_","");
                try {
                    notificationId = Integer.parseInt(tagid);
                }catch (NumberFormatException e){
                    notificationId = DOWNLOAD_TAG;
                    e.printStackTrace();
                }
            }
            PushJumpUtils.jumpToHomeActivityFormPush2(context,notificationId,message.getPushContent());
        }

//        DeviceMsgNotification.getInstance(context).updateMessage(message.getTargetId(),message.getPushContent());
        return true; // 返回 false, 会弹出融云 SDK 默认通知; 返回 true, 融云 SDK 不会弹通知, 通知需要由您自定义。
    }

    @Override
    public boolean onNotificationMessageClicked(Context context, PushNotificationMessage message) {
        Log.D(TAG,"融云推送消息被点击 message" + message.getPushContent());
        android.util.Log.d(TAG,"测试融云推送是否到达");
        PushJumpUtils.jumpToHomeActivityFormPush(context);
//        DeviceMsgNotification.getInstance(context).cancelNotification();
        return true; // 返回 false, 会走融云 SDK 默认处理逻辑, 即点击该通知会打开会话列表或会话界面; 返回 true, 则由您自定义处理逻辑。
    }

}
